from collections import Counter

def totalFruit(fruits) -> int:
    i, j, ans = 0, 0 , 0
    cout = Counter()
    # enumerate
    for j in range(len(fruits)):
        cout[fruits[j]] += 1
        while len(cout) > 2:
            cout[fruits[i]] -= 1
            if cout[fruits[i]] == 0:
                  cout.pop(fruits[i])
            i = i + 1
        ans = max(ans, j - i + 1)
    return ans

arr = [1,2,3,2,2]
num = totalFruit(arr)
print(num)